package yxy.game.pm2.command.niubee;

import yxy.cherry.game.base.message.MessageEmitterHandler;
import yxy.cherry.game.base.message.annotation.MessageSource;
import yxy.cherry.game.base.message.annotation.MessageType;
import yxy.game.pm2.Result;
import yxy.game.pm2.command.Command;
import yxy.game.pm2.message.NiuBeeMessage;
import yxy.game.pm2.module.niubee.NiuBeeHandle;

/** 神器 神器任务奖励领取 */
@MessageType(proto = Command.NiuBeeTaskBonus, classtype = NiuBeeMessage.NiuBeeTaskBonusRequest.class)
public class CMD_NiuBeeTaskBonus extends Command<NiuBeeMessage.NiuBeeTaskBonusRequest> {

	@Override
	public void execute(MessageSource messageSource, NiuBeeMessage.NiuBeeTaskBonusRequest request) {
		String playerCode = messageSource.getTag();
		String code = request.getCode();

		NiuBeeMessage.NiuBeeTaskBonusResponse.Builder response = NiuBeeMessage.NiuBeeTaskBonusResponse.newBuilder();

		try {
			Result result = new NiuBeeHandle().reward(playerCode, code, response);

			send(messageSource, response, result);
		} catch (Exception e) {
			send(messageSource, response, Result.ParamError);
		}

	}

	private void send(MessageSource messageSource, NiuBeeMessage.NiuBeeTaskBonusResponse.Builder response, Result result) {
		response.setResult(result.packResult());
		MessageEmitterHandler.getInstance().send(messageSource, response.build());
	}
}